﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Share_MenuTrai : System.Web.UI.UserControl
{
    public string mThuongHieu = "";
    public string mLoai = "";
    public string mXuatXu = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        
            string type = TTQT.TTQT_Code.TTQTCommon.isNull(Request["type"], "");
            string catid = TTQT.TTQT_Code.TTQTCommon.isNull(Request["catid"], "");

            string selectThuongHieu = "select NhomId,n.Name,count(*) as SoLuong from sanpham s inner join SanPham_Nhom n on s.NhomId=n.Id ";
            string selectLoai = "select L.id,L.Name,count(*) as SoLuong from sanpham s inner join SanPham_Loai L on s.LoaiId=L.Id ";
            string selectXuatXu = "select L.id,L.NoiSX,count(*) as SoLuong from sanpham s inner join SanPham_NoiSX L on s.NoiSXId=L.Id ";
            string groupByThuongHieu = " group by nhomid,Name";
            string groupByLoai = " group by L.ID,Name";
            string groupByXuatXu = " group by L.ID,NoiSX";

            string critial = "";
            switch (type)
            {
                case "sp":
                    {
                        catid = TTQT.TTQT_Code.TTQTCommon.isNull(Request["catid"], "");
                        critial = " and s.nhomId=" + catid;
                        break;
                    }
                case "khuyenmai":
                    {
                        critial = " where s.ChietKhau > 0";
                        break;
                    }
                case "banchay":
                    {
                        critial = " where s.banChay = 1";
                        break;
                    }
                case "hot":
                    {
                        critial = " where s.spHot = 1";
                        break;
                    }
            }
            
            string queryThuongHieu = selectThuongHieu + critial + groupByThuongHieu;
            string queryLoai = selectLoai + critial + groupByLoai;
            string queryXuatXu = selectXuatXu + critial + groupByXuatXu;

            CommonDAO c = new CommonDAO();
            
            DataTable t = c.queryForTable(queryThuongHieu, "t");
            foreach (DataRow r in t.Rows)
            {
                mThuongHieu += " <li class=\"field_title\"><a id ='Vendor_" + r["NhomId"] + "' onclick=\"FillerBy('Vendor'," + r["NhomId"] + ")\" href= 'javascript:void(0);'>" + r["name"] + " (" + r["SoLuong"] + ")</a></li>";
            }
           
            t = c.queryForTable(queryLoai, "t");
            foreach (DataRow r in t.Rows)
            {
                mLoai += " <li class=\"field_title\"><a id ='Type_" + r["Id"] + "' onclick=\"FillerBy('Type'," + r["Id"] + ")\" href= 'javascript:void(0);'>" + r["name"] + " (" + r["SoLuong"] + ")</a></li>";
            }

            t = c.queryForTable(queryXuatXu, "t");
            foreach (DataRow r in t.Rows)
            {
                mXuatXu += " <li class=\"field_title\"><a id ='MadeIn_" + r["Id"] + "' onclick=\"FillerBy('MadeIn'," + r["Id"] + ")\" href= 'javascript:void(0);'>" + r["NoiSX"] + " (" + r["SoLuong"] + ")</a></li>";
            }
            lblThuongHieu.Text = mThuongHieu;
            lblLoai.Text = mLoai;
            lblXuatXu.Text = mXuatXu;
        
    }
}
